package com.example.myproject

import android.os.Bundle
import android.widget.Button
import android.widget.ScrollView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MyScroll : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_my_scroll)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 获取ScrollView和Button的引用
        val scrollView = findViewById<ScrollView>(R.id.scrollView)
        val submitButton = findViewById<Button>(R.id.submitButton)

        // 设置按钮点击监听器，实现滚动置顶功能
        submitButton.setOnClickListener {
            // 平滑滚动到顶部
            scrollView.smoothScrollTo(0, 0)
        }
    }
}